#ifndef __CDATETIME_H__
#define __CDATETIME_H__

#include <ctime>
#include <string>
#include <sys/time.h>

class CDateTime
{
private:
    int m_us;
    int m_ms;
    time_t m_now;
    struct tm m_dateTime;
    struct timeval m_tval;

public:
    CDateTime();
    CDateTime(int year, int month, int day, int hour, int minute, int second);
    void Initialize();
    void InitTime(struct tm *date_time, time_t *time_now);
    void SetDateTimeByString(const std::string &datetimeStr);
    CDateTime &InitTimeStamp(time_t timestamp);
    CDateTime &AddDay(int day);
    CDateTime &AddMonth(int month);
    CDateTime &AddYear(int year);
    CDateTime &SubtractDay(int day);
    CDateTime &SubtractMonth(int month);
    CDateTime &SubtractYear(int year);
    bool operator>(const CDateTime &date_time) const;
    bool operator<(const CDateTime &date_time) const;
    bool operator==(const CDateTime &date_time) const;
    bool operator!=(const CDateTime &date_time) const;
    int GetYear() const;
    int GetMonth() const;
    int GetDay() const;
    int GetHour() const;
    int GetMinute() const;
    int GetSecond() const;
    int FormatYYYYMMDD();
    std::string FormatYYYYMMDDHHmmss();
    std::string FormatYYYYMMDDHHmmssSSS();
    std::string ToString() const;
    std::string Format(const char *formater = "%04d-%02d-%02d %02d:%02d:%02d.%03d.%03d");
};

#endif // __CDATETIME_H__
